package com.sixbing.android.topstatebar;

import android.content.Context;
import android.os.Build;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

import com.sixbing.android.topstatebar.util.NotchScreenUtil;

/**
 * desc :Notch Screen view
 * user : sixbing
 * time : 2019-08-02 17:00.
 * version : 1.0
 */
public class StateBarView extends View {
    private Context context;
    private int statusBarHeight;

    /**
     * StatusBarHeight
     *
     * @return StatusBarHeight  px
     */
    public int getStatusBarHeight() {
        return statusBarHeight;
    }
    public StateBarView(Context context) {
        super(context);
        this.context = context;
    }

    public StateBarView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }

    public StateBarView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//has state
            if (statusBarHeight == 0) {
                statusBarHeight = NotchScreenUtil.getStatusHeight(context);
            }
            setMeasuredDimension(widthMeasureSpec, statusBarHeight);
        } else {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }
}
